Skip to content

Add process configs endpoints for duplicate and getMetadata#74

Open
carojeandat wants to merge 8 commits intomainfrom
add-duplicate-process-config
Open

Add process configs endpoints for duplicate and getMetadata#74
carojeandat wants to merge 8 commits intomainfrom
add-duplicate-process-config

Conversation

@carojeandat
Copy link

@carojeandat carojeandat commented Mar 20, 2026

PR Summary

New endpoints to duplicate a ProcessConfig and to get its metadata (the processType)

@coderabbitai
Copy link

coderabbitai bot commented Mar 20, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Added two endpoints to ProcessConfigController: GET /v1/process-configs/metadata to fetch metadata for multiple process configs by IDs, and POST /v1/process-configs/duplication to duplicate a process config by UUID. Service methods and unit tests supporting both behaviors were added.

Changes

Cohort / File(s) Summary
Controller
monitor-server/src/main/java/org/gridsuite/monitor/server/controllers/ProcessConfigController.java
Added GET /v1/process-configs/metadata accepting ids: List<UUID> delegating to service and returning 200 with List<MetadataInfos>; added POST /v1/process-configs/duplication?duplicateFrom={uuid} delegating to service and returning 200 with new UUID or 404 when absent.
Service
monitor-server/src/main/java/org/gridsuite/monitor/server/services/processconfig/ProcessConfigService.java
Refactored create flow into doCreateProcessConfig(...); added @Transactional(readOnly = true) getProcessConfigsMetadata(List<UUID>) to load entities and map to MetadataInfos; added @Transactional duplicateProcessConfig(UUID) to duplicate a found entity and return new UUID or empty.
DTO
monitor-server/src/main/java/org/gridsuite/monitor/server/dto/processconfig/MetadataInfos.java
Added new record MetadataInfos(UUID id, ProcessType type) to represent minimal process-config metadata.
Controller Tests
monitor-server/src/test/java/org/gridsuite/monitor/server/controllers/ProcessConfigControllerTest.java
Added tests for GET /metadata verifying 200 + JSON list and service invocation; added duplication tests for success (200 + new UUID) and not-found (404), verifying service calls.
Service Tests
monitor-server/src/test/java/org/gridsuite/monitor/server/services/processconfig/ProcessConfigServiceTest.java
Added tests for getProcessConfigsMetadata() mapping entities to MetadataInfos; added duplication tests for found (returns new UUID and verifies save) and not-found (returns empty and verifies lookup only).

Sequence Diagram

sequenceDiagram
    participant Client
    participant Controller as ProcessConfigController
    participant Service as ProcessConfigService
    participant Repo as ProcessConfigRepository
    participant DB as Database

    Client->>Controller: POST /v1/process-configs/duplication?duplicateFrom={uuid}
    Controller->>Service: duplicateProcessConfig(sourceUuid)
    Service->>Repo: findById(sourceUuid)
    Repo->>DB: SELECT process_config
    DB-->>Repo: ProcessConfigEntity

    alt Source Found
        Repo-->>Service: Optional(ProcessConfigEntity)
        Service->>Service: map entity -> ProcessConfig DTO, prepare duplicate
        Service->>Repo: save(newEntity)
        Repo->>DB: INSERT process_config
        DB-->>Repo: Saved entity (id=newUuid)
        Repo-->>Service: Saved entity
        Service-->>Controller: Optional(newUuid)
        Controller-->>Client: 200 OK + newUuid
    else Source Not Found
        Repo-->>Service: Optional.empty
        Service-->>Controller: Optional.empty
        Controller-->>Client: 404 Not Found
    end
Loading

Suggested Reviewers

  • antoinebhs
  • khouadrired
  • FranckLecuyer
🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main changes: it adds two new endpoints for process configs (duplicate and getMetadata functionality).
Description check ✅ Passed The PR description accurately relates to the changeset, describing the addition of endpoints for process config duplication and metadata retrieval.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@carojeandat carojeandat changed the title Duplicate ProcessConfig Add process configs duplication endpoint Mar 20, 2026
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@monitor-server/src/test/java/org/gridsuite/monitor/server/controllers/ProcessConfigControllerTest.java`:
- Around line 153-165: Update the test duplicateSecurityAnalysisConfig() in
ProcessConfigControllerTest to assert the response body contains the returned
UUID: after the mockMvc.perform(...) call, add an expectation that the response
content equals newProcessConfigId.toString() (e.g.,
andExpect(content().string(newProcessConfigId.toString()))), keeping the
existing status assertion and the verify of
processConfigService.duplicateProcessConfig(any(UUID.class)).

In
`@monitor-server/src/test/java/org/gridsuite/monitor/server/services/processconfig/ProcessConfigServiceTest.java`:
- Around line 147-153: The two empty test methods in ProcessConfigServiceTest
must exercise the service method duplicateProcessConfig: implement one test
(duplicateSecurityAnalysisConfig) that sets up a mock repository to return an
existing ProcessConfig when findById(...) is called, invokes
ProcessConfigService.duplicateProcessConfig(id), asserts the returned Optional
contains a new UUID different from the source id, and verifies
repository.save(...) was called with an entity that copies the relevant fields
from the source (name, settings, etc.) but has a new id; implement the second
test (duplicateSecurityAnalysisConfigNotFound) to have the repository return
Optional.empty(), call duplicateProcessConfig(id), and assert Optional.empty()
is returned and repository.save(...) is never called. Ensure you reference the
service method duplicateProcessConfig and repository.save/findById in the mocks
and assertions to validate behavior.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: b3677d95-3cac-4002-97a4-e08181bc7048

📥 Commits

Reviewing files that changed from the base of the PR and between c216da6 and 4342c6c.

📒 Files selected for processing (4)
  • monitor-server/src/main/java/org/gridsuite/monitor/server/controllers/ProcessConfigController.java
  • monitor-server/src/main/java/org/gridsuite/monitor/server/services/processconfig/ProcessConfigService.java
  • monitor-server/src/test/java/org/gridsuite/monitor/server/controllers/ProcessConfigControllerTest.java
  • monitor-server/src/test/java/org/gridsuite/monitor/server/services/processconfig/ProcessConfigServiceTest.java

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@monitor-server/src/main/java/org/gridsuite/monitor/server/services/processconfig/ProcessConfigService.java`:
- Around line 69-73: duplicateProcessConfig currently calls
processConfigRepository.save(sourceEntity) which will merge the existing entity
instead of inserting a new row; change the logic in ProcessConfigService. In
duplicateProcessConfig(UUID) fetch the source via
processConfigRepository.findById, create a new ProcessConfig instance (or
deep/shallow copy relevant fields from sourceEntity) and ensure its id is
null/cleared (and detach/avoid using the same entity instance), then call
processConfigRepository.save(newEntity) so JPA inserts a new record and returns
a new UUID; also copy or reset any relationship IDs, audit fields, or unique
constraints as appropriate before saving.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 9f0a8841-eb67-4643-aea9-4f44d1ec4428

📥 Commits

Reviewing files that changed from the base of the PR and between 4342c6c and 6d66f6a.

📒 Files selected for processing (3)
  • monitor-server/src/main/java/org/gridsuite/monitor/server/services/processconfig/ProcessConfigService.java
  • monitor-server/src/test/java/org/gridsuite/monitor/server/controllers/ProcessConfigControllerTest.java
  • monitor-server/src/test/java/org/gridsuite/monitor/server/services/processconfig/ProcessConfigServiceTest.java
✅ Files skipped from review due to trivial changes (1)
  • monitor-server/src/test/java/org/gridsuite/monitor/server/controllers/ProcessConfigControllerTest.java
🚧 Files skipped from review as they are similar to previous changes (1)
  • monitor-server/src/test/java/org/gridsuite/monitor/server/services/processconfig/ProcessConfigServiceTest.java

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
monitor-server/src/test/java/org/gridsuite/monitor/server/services/processconfig/ProcessConfigServiceTest.java (1)

170-192: Test uses a mock entity and doesn't verify that fields are correctly copied.

Using mock(SecurityAnalysisConfigEntity.class) at line 176 returns an entity where all getters return null (or default values). This means the test doesn't verify that the duplication logic correctly copies fields from the source entity to the new one.

The ArgumentCaptor is created (line 190) but never used to assert the saved entity's fields. Compare this to createSecurityAnalysisConfig (lines 77-81) which verifies the saved entity's fields.

♻️ Suggested improvement to verify duplication behavior
     `@Test`
     void duplicateSecurityAnalysisConfig() {
         UUID processConfigId = UUID.randomUUID();
         UUID expectedNewProcessConfigId = UUID.randomUUID();

+        SecurityAnalysisConfigEntity sourceEntity = securityAnalysisConfigMapper.toEntity(securityAnalysisConfig);
+        sourceEntity.setId(processConfigId);
+
         when(processConfigRepository.findById(processConfigId))
-            .thenReturn(Optional.of(mock(SecurityAnalysisConfigEntity.class)));
+            .thenReturn(Optional.of(sourceEntity));
         when(processConfigRepository.save(any(SecurityAnalysisConfigEntity.class)))
             .thenAnswer(invocation -> {
                 SecurityAnalysisConfigEntity entity = invocation.getArgument(0);
                 entity.setId(expectedNewProcessConfigId);
                 return entity;
             });

         Optional<UUID> newProcessConfigId = processConfigService.duplicateProcessConfig(processConfigId);

         assertThat(newProcessConfigId).isPresent();
         assertThat(newProcessConfigId.get()).isEqualTo(expectedNewProcessConfigId);

         verify(processConfigRepository).findById(processConfigId);
         ArgumentCaptor<SecurityAnalysisConfigEntity> captor = ArgumentCaptor.forClass(SecurityAnalysisConfigEntity.class);
         verify(processConfigRepository).save(captor.capture());
+
+        SecurityAnalysisConfigEntity savedEntity = captor.getValue();
+        assertThat(savedEntity.getSecurityAnalysisParametersUuid()).isEqualTo(securityAnalysisConfig.securityAnalysisParametersUuid());
+        assertThat(savedEntity.getModificationUuids()).isEqualTo(securityAnalysisConfig.modificationUuids());
+        assertThat(savedEntity.getLoadflowParametersUuid()).isEqualTo(securityAnalysisConfig.loadflowParametersUuid());
     }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@monitor-server/src/test/java/org/gridsuite/monitor/server/services/processconfig/ProcessConfigServiceTest.java`
around lines 170 - 192, The test duplicateSecurityAnalysisConfig uses
mock(SecurityAnalysisConfigEntity.class) which yields empty/default getters so
it doesn't verify field copying; replace the mock with a real
SecurityAnalysisConfigEntity instance populated with representative field values
(set the fields the duplication logic should copy), continue stubbing
processConfigRepository.save(...) to assign expectedNewProcessConfigId, then use
the existing ArgumentCaptor<SecurityAnalysisConfigEntity> captor from
verify(processConfigRepository).save(...) and add assertions that
captor.getValue() contains the same field values as the original entity (and
that its id is the new UUID if applicable) to validate duplication semantics in
ProcessConfigService.duplicateProcessConfig.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In
`@monitor-server/src/test/java/org/gridsuite/monitor/server/services/processconfig/ProcessConfigServiceTest.java`:
- Around line 170-192: The test duplicateSecurityAnalysisConfig uses
mock(SecurityAnalysisConfigEntity.class) which yields empty/default getters so
it doesn't verify field copying; replace the mock with a real
SecurityAnalysisConfigEntity instance populated with representative field values
(set the fields the duplication logic should copy), continue stubbing
processConfigRepository.save(...) to assign expectedNewProcessConfigId, then use
the existing ArgumentCaptor<SecurityAnalysisConfigEntity> captor from
verify(processConfigRepository).save(...) and add assertions that
captor.getValue() contains the same field values as the original entity (and
that its id is the new UUID if applicable) to validate duplication semantics in
ProcessConfigService.duplicateProcessConfig.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: fb6a5a71-e32c-4535-bf4b-f85b234090df

📥 Commits

Reviewing files that changed from the base of the PR and between e4fa2a1 and 440b210.

📒 Files selected for processing (5)
  • monitor-server/src/main/java/org/gridsuite/monitor/server/controllers/ProcessConfigController.java
  • monitor-server/src/main/java/org/gridsuite/monitor/server/dto/processconfig/MetadataInfos.java
  • monitor-server/src/main/java/org/gridsuite/monitor/server/services/processconfig/ProcessConfigService.java
  • monitor-server/src/test/java/org/gridsuite/monitor/server/controllers/ProcessConfigControllerTest.java
  • monitor-server/src/test/java/org/gridsuite/monitor/server/services/processconfig/ProcessConfigServiceTest.java
✅ Files skipped from review due to trivial changes (1)
  • monitor-server/src/main/java/org/gridsuite/monitor/server/dto/processconfig/MetadataInfos.java
🚧 Files skipped from review as they are similar to previous changes (1)
  • monitor-server/src/main/java/org/gridsuite/monitor/server/services/processconfig/ProcessConfigService.java

@carojeandat carojeandat changed the title Add process configs duplication endpoint Add process configs endpoints for duplicate and getMetadata Mar 25, 2026
}

@Test
void duplicateSecurityAnalysisConfig() throws Exception {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a use case where the process config is not securityAnalysis

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, the type of ProcessConfig is never specified in this test, so it applies to any type. I renamed the test from duplicateSecurityAnalysisConfig to duplicateProcessConfig.

@sonarqubecloud
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants